///用来封装网络请求的

const baseUrl = 'http://47.91.230.137:8086'
const request = (options = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + options.url || '',
			method: options.type || 'GET',



			data: options.data || {},
			header: {
				"X-Litemall-Token": uni.getStorageSync('token')
			} || {},
			success: response => {
				// debugger
				if (response.data.errno == 0) { //表述请求操作成功
					resolve(response.data); //正常的返回
				} else {
					uni.showToast({
						title: response.data.errmsg,
						icon: 'none',
						duration: 2000
					})
				}
			},
			fail: res => {
				reject(res) //异常返回
			}
		})
	});
}
const get = (url, data, options = {}) => {
	options.type = 'get';
	options.data = data;
	options.url = url;
	return request(options)
}
const post = (url, data, options = {}) => {
	options.type = 'post';
	options.data = data;
	options.url = url;
	return request(options)
}
const put = (url, data, options = {}) => {
	options.type = 'put';
	options.data = data;
	options.url = url;
	return request(options)
}
const deletes = (url, data, options = {}) => {
	options.type = 'delete';
	options.data = data;
	options.url = url;
	return request(options)
}
export default {
	request,
	get,
	post,
	put,
	baseUrl,
	deletes
}